package com.wc5818.other.renrunyun;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.wc5818.other.ToKenCell;
import com.wc5818.service.UserService;

/***
 * 
 * @author yqb 大数据接口
 *
 */
public class RRY {

	/**
	 * 构造函数
	 */
	public RRY() {

		stoken = getToken().getData().getAccessToken();

		 

	}

	private static String stoken = "";

	private static String uname = "wanchewansong123";
	private static String secret = "S6R3G7Y2m8U8Z3w8t";

	/****
	 * 获取token URL
	 */

	private static String verifytoken = "https://api.zhenjinfengkong.com/risk/data/api/getAccessToken";
	/***
	 * 身份证卡访问地址
	 */
	private static String IDCardURL = "https://api.zhenjinfengkong.com/risk/data/idcard/verify";
	/**
	 * 银行卡3要素访问地址
	 */
	private static String bankCard3 = "https://api.zhenjinfengkong.com/risk/data/bankCard3/verify";

	/***
	 * 
	 */
	private static String bankCardOwnerquery = "https://api.zhenjinfengkong.com/risk/data/bankCardOwner/query";
	/**
	 * 多头借贷访问地址
	 */
	private static String bulllending = "https://api.zhenjinfengkong.com/risk/data/bulllending/verify";

	/***
	 * 驾驶证查询
	 */
	private static String driverinfo = "https://api.zhenjinfengkong.com/risk/data/driver/info";

	/**
	 * 个人涉诉信息 lawquery
	 */
	private static String lawquery = "https://api.zhenjinfengkong.com/api/person/law/query";
	/***
	 * 公安不良信息 criminalquery
	 */
	private static String criminalquery = "https://api.zhenjinfengkong.com/api/person/criminal/query";

	/**
	 * 反欺诈 doBodyguard
	 */
	private static String doBodyguard = "https://api.zhenjinfengkong.com/risk/data/bodyguard/doBodyguard";

	/***
	 * createTask 网贷黑名单
	 */
	private static String createTask = "https://api.zhenjinfengkong.com/risk/data/nocredit/createTask";

	/***
	 * 个人征信全信息查询 mateDataquery
	 */
	private static String q = "https://api.zhenjinfengkong.com/risk/data/mateData/query";

	/***
	 * 全局原生态请求
	 */
	private static String maps = "{\"uname\":\"" + uname + "\",\"secret\":\"" + secret + "\"}";

	/****
	 * 接入
	 * 
	 * @param name
	 * @param idCard
	 * @param token
	 * @return
	 */
	public String getIDCard(String name, String idCard, String token) {

		// String mpas = "{\"uname\":\""+uname+"\",\"secret\":\""+secret+"\"}";
//		HttpHeaders headers = new HttpHeaders();
//		headers.add("Content-Type", "application/json;charset=utf-8");
//		headers.add("access-token", "");
//		
//		HttpEntity<JSONObject> requestEntity = new HttpEntity<JSONObject>(null, headers);
//		
//		
//		Map<String, Object> map = new HashMap<>();
//		map.put("name", name);
//		map.put("idCard", idCard);
//	 
//		RestTemplate mmmm = new RestTemplate();
//		mmmm.exchange(requestEntity, JSONObject.class);
//		 
//		return jsonObjectResult.getBody();

		return "";
	}

	/**
	 * 获取token
	 * 
	 * @param uname
	 * @param secret
	 * @return
	 */
	public ToKenCell getToken() {

//		  
//
//		
//		RestTemplate restTemplate = new RestTemplate();

//		
//		
//		Map<String, Object> map = new HashMap<>();
//		map.put("uname", "wanchewansong123");
//		map.put("secret","S6R3G7Y2m8U8Z3w8t");
//		
//		
//		HttpHeaders headers = new HttpHeaders();
//		headers.add("Content-Type", "application/json;charset=utf-8");
//		HttpEntity<String> requestEntity = new HttpEntity<String>(headers);
//		
//		
//		
//		ResponseEntity<String> jsonObjectResult = restTemplate.exchange(verifytoken, HttpMethod.POST, requestEntity, String.class, map);
//		System.out.println(jsonObjectResult.getBody());
//		
//		
//		
//		return restTemplate.postForEntity(verifytoken, mpas, ToKenCell.class).getBody();
//		
//		
		HttpHeaders requestHeaders = new HttpHeaders();
		requestHeaders.add("Content-Type", "application/json;charset=utf-8");

		// HttpEntity
		HttpEntity<String> requestEntity = new HttpEntity<String>(maps, requestHeaders);
		RestTemplate restTemplate = new RestTemplate();
		// post
		ResponseEntity<ToKenCell> responseEntity = restTemplate.postForEntity(verifytoken, requestEntity,
				ToKenCell.class);

		return responseEntity.getBody();

	}

	/**
	 * 获取验证身份
	 * 
	 * @param name
	 * @param idCard
	 * @return
	 */
	public String getidcardverify(String name, String idCard) {

		HttpHeaders requestHeaders = new HttpHeaders();
		requestHeaders.add("Content-Type", "application/json;charset=utf-8");
		requestHeaders.add("access-token", stoken);

		/***
		 * 全局原生态请求
		 */
		String bodys = "{\"name\":\"" + name + "\",\"idCard\":\"" + idCard + "\"}";
		// HttpEntity
		HttpEntity<String> requestEntity = new HttpEntity<String>(bodys, requestHeaders);
		RestTemplate restTemplate = new RestTemplate();
		// post
		ResponseEntity<String> responseEntity = restTemplate.postForEntity(IDCardURL, requestEntity, String.class);

		return responseEntity.getBody();

	}

	/**
	 * 获取银行卡3要素验证
	 * 
	 * @param name
	 * @param idCard
	 * @return
	 */
	public String getbankCard3verify(String name, String idCard, String mobile, String bankcard) {

		HttpHeaders requestHeaders = new HttpHeaders();
		requestHeaders.add("Content-Type", "application/json;charset=utf-8");
		requestHeaders.add("access-token", stoken);

		/***
		 * 全局原生态请求
		 * "{\"name\":\""+name+"\",\"idCard\":\""+idCard+"\",\"mobile\":\""+mobile+"\",\"bankcard\":\""+bankcard+"\"}";
		 */
		String bodys = "{\"name\":\"" + name + "\",\"idCard\":\"" + idCard + "\",\"mobile\":\"" + mobile
				+ "\",\"bankcard\":\"" + bankcard + "\"}";
		// HttpEntity
		HttpEntity<String> requestEntity = new HttpEntity<String>(bodys, requestHeaders);
		RestTemplate restTemplate = new RestTemplate();
		// post
		ResponseEntity<String> responseEntity = restTemplate.postForEntity(bankCard3, requestEntity, String.class);

		return responseEntity.getBody();

	}

	/***
	 * 驾驶证查询
	 * @param name
	 * @param idCard
 
	 * @return
	 */
	public String getdriverinfo(String name, String idCard) {

		HttpHeaders requestHeaders = new HttpHeaders();
		requestHeaders.add("Content-Type", "application/json;charset=utf-8");
		requestHeaders.add("access-token", stoken);

		/***
		 * 全局原生态请求
		 * "{\"name\":\""+name+"\",\"idCard\":\""+idCard+"\",\"mobile\":\""+mobile+"\",\"bankcard\":\""+bankcard+"\"}";
		 */
		String bodys = "{\"name\":\"" + name + "\",\"idCard\":\"" + idCard + "\"}";
		// HttpEntity
		HttpEntity<String> requestEntity = new HttpEntity<String>(bodys, requestHeaders);
		RestTemplate restTemplate = new RestTemplate();
		// post
		ResponseEntity<String> responseEntity = restTemplate.postForEntity(driverinfo, requestEntity, String.class);

		return responseEntity.getBody();

	}
	
	/**
	 * bulllending/verify
	 * 多头借贷
	 * 
	 */
	
	public String getbulllendingverify(String name, String idCard,String mobile) {

		HttpHeaders requestHeaders = new HttpHeaders();
		requestHeaders.add("Content-Type", "application/json;charset=utf-8");
		requestHeaders.add("access-token", stoken);

		/***
		 * 全局原生态请求
		 * "{\"name\":\""+name+"\",\"idCard\":\""+idCard+"\",\"mobile\":\""+mobile+"\",\"bankcard\":\""+bankcard+"\"}";
		 */
		String bodys = "{\"name\":\"" + name + "\",\"idCard\":\"" + idCard + "\",\"mobile\":\"" + mobile + "\"}";
		// HttpEntity
		HttpEntity<String> requestEntity = new HttpEntity<String>(bodys, requestHeaders);
		RestTemplate restTemplate = new RestTemplate();
		// post
		ResponseEntity<String> responseEntity = restTemplate.postForEntity(bulllending, requestEntity, String.class);

		return responseEntity.getBody();

	}
	/***
	 * lawquery
	 * 个人涉诉
	 */
	
	public String getlawquery(String name, String idCard) {

		HttpHeaders requestHeaders = new HttpHeaders();
		requestHeaders.add("Content-Type", "application/json;charset=utf-8");
		requestHeaders.add("access-token", stoken);

		/***
		 * 全局原生态请求
		 * "{\"name\":\""+name+"\",\"idCard\":\""+idCard+"\",\"mobile\":\""+mobile+"\",\"bankcard\":\""+bankcard+"\"}";
		 */
		String bodys = "{\"name\":\"" + name + "\",\"idCard\":\"" + idCard + "\"}";
		// HttpEntity
		HttpEntity<String> requestEntity = new HttpEntity<String>(bodys, requestHeaders);
		RestTemplate restTemplate = new RestTemplate();
		// post
		ResponseEntity<String> responseEntity = restTemplate.postForEntity(lawquery, requestEntity, String.class);

		return responseEntity.getBody();

	}
	

	/***
	 * 银行卡归属地
	 * 
	 * @param bankcard
	 * @return
	 */
	public String getbankCardOwnerquery(String bankcard) {

		HttpHeaders requestHeaders = new HttpHeaders();
		requestHeaders.add("Content-Type", "application/json;charset=utf-8");
		requestHeaders.add("access-token", stoken);

		/***
		 * 全局原生态请求
		 * "{\"name\":\""+name+"\",\"idCard\":\""+idCard+"\",\"mobile\":\""+mobile+"\",\"bankcard\":\""+bankcard+"\"}";
		 */
		String bodys = "{\"bankcard\":\"" + bankcard + "\"}";
		RestTemplate restTemplate = new RestTemplate();

		HttpEntity<String> requestEntity = new HttpEntity<String>(bodys, requestHeaders);
		ResponseEntity<String> response = restTemplate.exchange(bankCard3, HttpMethod.GET, requestEntity, String.class);
		String sttr = response.getBody();

		// HttpEntity
		// HttpEntity<String> requestEntity = new HttpEntity<String>(bodys,
		// requestHeaders);

		// post

		// ResponseEntity<String> responseEntity = restTemplate.postForEntity(bankCard3,
		// requestEntity, String.class);

		return sttr;

	}

}
